﻿//////////////////////////////////////////////////////////////////////////////
//
// Copyright © 1998-2024 Glodon Company Limited.
//
// Licensed under the MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the “Software”),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//////////////////////////////////////////////////////////////////////////////
#include "FaceStyleSettingDialog.h"

#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QLabel>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QVBoxLayout>
#include <QtWidgets/QWidget>
#include <QtWidgets/QColorDialog>
#include <QColor>

#include "IFaceHatchPattern.h"
#include "IFillPattern.h"
#include "IFillPatternData.h"
#include "GcmpBuiltInCategoryUniIdentities.h"
#include "IElement.h"
#include "IGenericElement.h"
#include "EnableCompileWarning_The_LAST_IncludeInCpp.h"

CREATE_DEBUG_MODE(DontUseSectionFaceColor, L"不使用截面颜色", gcmp::DebugModeGroup::DMGT_RENDERING, L"GDMPLab", L"2023-12-20",
    L"打开这个开关，样式对话框上的截面颜色将直接使用面颜色，用以兼容老的模式。");

using namespace gcmp;

FaceStyleSettingDialog::FaceStyleSettingDialog(gcmp::IDocument * doc, const gcmp::UniIdentity& categoryUid, const gcmp::Color& faceColor, const gcmp::Color& sectionFaceColor,
    const gcmp::Color& projectionFaceHatchColor, const std::wstring& projectionFaceHatchPattern, const double projectionFaceHatchAngle, const double projectionFaceHatchScale, const gcmp::Color& sectionFaceHatchColor,
    const std::wstring& sectionFaceHatchPattern, const double sectionHatchAngle, const double sectionHatchScale)
    : m_doc(doc)
    , m_categoryUid(categoryUid)
    , m_faceColor(faceColor)
    , m_sectionFaceColor(sectionFaceColor)
    , m_projectionFaceHatchColor(projectionFaceHatchColor)
    , m_projectionFaceHatchPattern(projectionFaceHatchPattern)
    , m_projectionFaceHatchAngle(projectionFaceHatchAngle)
    , m_projectionFaceHatchScale(projectionFaceHatchScale)
    , m_sectionFaceHatchColor(sectionFaceHatchColor)
    , m_sectionFaceHatchPattern(sectionFaceHatchPattern)
    , m_sectionHatchAngle(sectionHatchAngle)
    , m_sectionHatchScale(sectionHatchScale)
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_doc, L"文档为空",L"GDMPLab",L"2024-03-30");

    QWidget *centralWidget;
    QGroupBox *groupBoxShading;
    QWidget *horizontalLayoutWidget;
    QHBoxLayout* horizontalLayout;
    QVBoxLayout* verticalLayoutShading1;
    QLabel* labelFaceColor;
    QLabel* labelSectionFaceColor;
    QVBoxLayout* verticalLayoutShading2;
    
    QGroupBox *groupBoxProjectionFaceFilling;
    QWidget *horizontalLayoutWidget_3;
    QHBoxLayout *horizontalLayoutProjectionFaceFilling;
    QVBoxLayout *verticalLayoutProjectionFaceFilling1;
    QLabel *labelProjectionFaceFillingColor;
    QLabel *labelProjectionFaceFillingHatchPattern;
    QLabel *labelProjectionFaceFillingAngle;
    QLabel *labelProjectionFaceFillingScale;
    QVBoxLayout *verticalLayoutProjectionFaceFilling2;   
    QGroupBox *groupBoxSectionFilling;
    QWidget *horizontalLayoutWidget_4;
    QHBoxLayout *horizontalLayoutSectionFilling;
    QVBoxLayout *verticalLayoutSectionFilling1;
    QLabel *labelSectionFillingColor;
    QLabel *labelSectionFillingHatchPattern;
    QLabel *labelSectionFillingAngle;
    QLabel *labelSectionFillingScale;
    QVBoxLayout *verticalLayoutSectionFilling2;
    
    QPushButton *pushButtonOk;
    QPushButton *pushButtonCancel;

    if (this->objectName().isEmpty())
        this->setObjectName(QStringLiteral("FaceStyleSettingDialogClass"));
    this->setFixedSize(292, 380);
    centralWidget = NEW_AS_QT_CHILD(QWidget, this); 
    centralWidget->setObjectName(QStringLiteral("centralWidget"));
    groupBoxShading = NEW_AS_QT_CHILD(QGroupBox, centralWidget);
    groupBoxShading->setObjectName(QStringLiteral("groupBoxShading"));
    groupBoxShading->setGeometry(QRect(10, 10, 269, 81));
    groupBoxShading->setFlat(false);
    horizontalLayoutWidget = NEW_AS_QT_CHILD(QWidget, groupBoxShading);
    horizontalLayoutWidget->setObjectName(QStringLiteral("horizontalLayoutWidget"));
    horizontalLayoutWidget->setGeometry(QRect(10, 10, 251, 61));
    horizontalLayout = NEW_AS_QT_CHILD(QHBoxLayout, horizontalLayoutWidget);
    horizontalLayout->setSpacing(6);
    horizontalLayout->setContentsMargins(11, 11, 11, 11);
    horizontalLayout->setObjectName(QStringLiteral("horizontalLayout"));
    horizontalLayout->setContentsMargins(0, 0, 0, 0);
    verticalLayoutShading1 = TRANSFER_OWNERSHIP_TO_THIRD_PARTY(NEW_AS_OWNER_PTR(QVBoxLayout));
    verticalLayoutShading1->setSpacing(6);
    verticalLayoutShading1->setObjectName(QStringLiteral("verticalLayoutShading1"));
    labelFaceColor = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget);
    labelFaceColor->setObjectName(QStringLiteral("labelFaceColor"));

    verticalLayoutShading1->addWidget(labelFaceColor);

    labelSectionFaceColor = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget);
    labelSectionFaceColor->setObjectName(QStringLiteral("labelSectionFaceColor"));

    verticalLayoutShading1->addWidget(labelSectionFaceColor);

    horizontalLayout->addLayout(verticalLayoutShading1);

    verticalLayoutShading2 = TRANSFER_OWNERSHIP_TO_THIRD_PARTY(NEW_AS_OWNER_PTR(QVBoxLayout));
    verticalLayoutShading2->setSpacing(6);
    verticalLayoutShading2->setObjectName(QStringLiteral("verticalLayoutShading2"));

    m_pPushButtonFaceColor = NEW_AS_QT_CHILD(QPushButton, horizontalLayoutWidget);
    m_pPushButtonFaceColor->setObjectName(QStringLiteral("pushButtonFaceColor"));
    m_pPushButtonFaceColor->setAutoFillBackground(false);
    m_pPushButtonFaceColor->setAutoDefault(false);
    m_pPushButtonFaceColor->setDefault(false);
    m_pPushButtonFaceColor->setFlat(false);

    verticalLayoutShading2->addWidget(m_pPushButtonFaceColor);

    m_pPushButtonSectionFaceColor = NEW_AS_QT_CHILD(QPushButton, horizontalLayoutWidget);
    m_pPushButtonSectionFaceColor->setObjectName(QStringLiteral("pushButtonSectionFaceColor"));
    m_pPushButtonSectionFaceColor->setAutoFillBackground(false);
    m_pPushButtonSectionFaceColor->setAutoDefault(false);
    m_pPushButtonSectionFaceColor->setDefault(false);
    m_pPushButtonSectionFaceColor->setFlat(false);

    verticalLayoutShading2->addWidget(m_pPushButtonSectionFaceColor);
    horizontalLayout->addLayout(verticalLayoutShading2);

    groupBoxProjectionFaceFilling = NEW_AS_QT_CHILD(QGroupBox, centralWidget);
    groupBoxProjectionFaceFilling->setObjectName(QStringLiteral("groupBoxProjectionFaceFilling"));
    groupBoxProjectionFaceFilling->setGeometry(QRect(10, 100, 269, 110));
    horizontalLayoutWidget_3 = NEW_AS_QT_CHILD(QWidget, groupBoxProjectionFaceFilling);
    horizontalLayoutWidget_3->setObjectName(QStringLiteral("horizontalLayoutWidget_3"));
    horizontalLayoutWidget_3->setGeometry(QRect(10, 20, 251, 80));
    horizontalLayoutProjectionFaceFilling = NEW_AS_QT_CHILD(QHBoxLayout, horizontalLayoutWidget_3);
    horizontalLayoutProjectionFaceFilling->setSpacing(6);
    horizontalLayoutProjectionFaceFilling->setContentsMargins(11, 11, 11, 11);
    horizontalLayoutProjectionFaceFilling->setObjectName(QStringLiteral("horizontalLayoutProjectionFaceFilling"));
    horizontalLayoutProjectionFaceFilling->setContentsMargins(0, 0, 0, 0);
    verticalLayoutProjectionFaceFilling1 = TRANSFER_OWNERSHIP_TO_THIRD_PARTY(NEW_AS_OWNER_PTR(QVBoxLayout));
    verticalLayoutProjectionFaceFilling1->setSpacing(6);
    verticalLayoutProjectionFaceFilling1->setObjectName(QStringLiteral("verticalLayoutProjectionFaceFilling1"));
    labelProjectionFaceFillingColor = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget_3);
    labelProjectionFaceFillingColor->setObjectName(QStringLiteral("labelProjectionFaceFillingColor"));

    verticalLayoutProjectionFaceFilling1->addWidget(labelProjectionFaceFillingColor);

    labelProjectionFaceFillingHatchPattern = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget_3);
    labelProjectionFaceFillingHatchPattern->setObjectName(QStringLiteral("labelProjectionFaceFillingHatchPattern"));

    verticalLayoutProjectionFaceFilling1->addWidget(labelProjectionFaceFillingHatchPattern);
    labelProjectionFaceFillingAngle = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget_3);
    labelProjectionFaceFillingAngle->setObjectName(QStringLiteral("labelProjectionFaceFillingAngle"));
    verticalLayoutProjectionFaceFilling1->addWidget(labelProjectionFaceFillingAngle);

    labelProjectionFaceFillingScale = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget_3);
    labelProjectionFaceFillingScale->setObjectName(QStringLiteral("labelProjectionFaceFillingScale"));
    verticalLayoutProjectionFaceFilling1->addWidget(labelProjectionFaceFillingScale);

    horizontalLayoutProjectionFaceFilling->addLayout(verticalLayoutProjectionFaceFilling1);

    verticalLayoutProjectionFaceFilling2 = TRANSFER_OWNERSHIP_TO_THIRD_PARTY(NEW_AS_OWNER_PTR(QVBoxLayout));
    verticalLayoutProjectionFaceFilling2->setSpacing(6);
    verticalLayoutProjectionFaceFilling2->setObjectName(QStringLiteral("verticalLayoutProjectionFaceFilling2"));
    m_pPushButtonProjectionFaceFillingColor = NEW_AS_QT_CHILD(QPushButton, horizontalLayoutWidget_3);
    m_pPushButtonProjectionFaceFillingColor->setObjectName(QStringLiteral("pushButtonProjectionFaceFillingColor"));

    verticalLayoutProjectionFaceFilling2->addWidget(m_pPushButtonProjectionFaceFillingColor);

    m_pComboBoxProjectionFaceHatchPattern = NEW_AS_QT_CHILD(QComboBox, horizontalLayoutWidget_3);
    m_pComboBoxProjectionFaceHatchPattern->setObjectName(QStringLiteral("comboBoxProjectionFaceHatchPattern"));

    verticalLayoutProjectionFaceFilling2->addWidget(m_pComboBoxProjectionFaceHatchPattern);


    m_pLineEditProjectionFaceHatchAngle = NEW_AS_QT_CHILD(QLineEdit, horizontalLayoutWidget_3);
    m_pLineEditProjectionFaceHatchAngle->setObjectName(QStringLiteral("lineEditProjectionFaceHatchAngle"));

    verticalLayoutProjectionFaceFilling2->addWidget(m_pLineEditProjectionFaceHatchAngle);


    m_pLineEditProjectionFaceHatchScale = NEW_AS_QT_CHILD(QLineEdit, horizontalLayoutWidget_3);
    m_pLineEditProjectionFaceHatchScale->setObjectName(QStringLiteral("lineEditProjectionFaceHatchScale"));

    verticalLayoutProjectionFaceFilling2->addWidget(m_pLineEditProjectionFaceHatchScale);
    horizontalLayoutProjectionFaceFilling->addLayout(verticalLayoutProjectionFaceFilling2);

    horizontalLayoutWidget_3->raise();
    groupBoxSectionFilling = NEW_AS_QT_CHILD(QGroupBox, centralWidget);
    groupBoxSectionFilling->setObjectName(QStringLiteral("groupBoxSectionFilling"));
    groupBoxSectionFilling->setGeometry(QRect(10, 220, 269, 110));
    horizontalLayoutWidget_4 = NEW_AS_QT_CHILD(QWidget, groupBoxSectionFilling);
    horizontalLayoutWidget_4->setObjectName(QStringLiteral("horizontalLayoutWidget_4"));
    horizontalLayoutWidget_4->setGeometry(QRect(9, 20, 251, 80));
    horizontalLayoutSectionFilling = NEW_AS_QT_CHILD(QHBoxLayout, horizontalLayoutWidget_4);
    horizontalLayoutSectionFilling->setSpacing(6);
    horizontalLayoutSectionFilling->setContentsMargins(11, 11, 11, 11);
    horizontalLayoutSectionFilling->setObjectName(QStringLiteral("horizontalLayoutSectionFilling"));
    horizontalLayoutSectionFilling->setContentsMargins(0, 0, 0, 0);
    verticalLayoutSectionFilling1 = TRANSFER_OWNERSHIP_TO_THIRD_PARTY(NEW_AS_OWNER_PTR(QVBoxLayout));
    verticalLayoutSectionFilling1->setSpacing(6);
    verticalLayoutSectionFilling1->setObjectName(QStringLiteral("verticalLayoutSectionFilling1"));
    labelSectionFillingColor = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget_4);
    labelSectionFillingColor->setObjectName(QStringLiteral("labelSectionFillingColor"));

    verticalLayoutSectionFilling1->addWidget(labelSectionFillingColor);

    labelSectionFillingHatchPattern = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget_4);
    labelSectionFillingHatchPattern->setObjectName(QStringLiteral("labelSectionFillingHatchPattern"));

    verticalLayoutSectionFilling1->addWidget(labelSectionFillingHatchPattern);
    labelSectionFillingAngle = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget_4);
    labelSectionFillingAngle->setObjectName(QStringLiteral("labelSectionFillingAngle"));
    verticalLayoutSectionFilling1->addWidget(labelSectionFillingAngle);

    labelSectionFillingScale = NEW_AS_QT_CHILD(QLabel, horizontalLayoutWidget_4);
    labelSectionFillingScale->setObjectName(QStringLiteral("labelSectionFillingScale"));
    verticalLayoutSectionFilling1->addWidget(labelSectionFillingScale);

    horizontalLayoutSectionFilling->addLayout(verticalLayoutSectionFilling1);

    verticalLayoutSectionFilling2 = TRANSFER_OWNERSHIP_TO_THIRD_PARTY(NEW_AS_OWNER_PTR(QVBoxLayout));
    verticalLayoutSectionFilling2->setSpacing(6);
    verticalLayoutSectionFilling2->setObjectName(QStringLiteral("verticalLayoutSectionFilling2"));
    m_pPushButtonSectionFillingColor = NEW_AS_QT_CHILD(QPushButton, horizontalLayoutWidget_4);
    m_pPushButtonSectionFillingColor->setObjectName(QStringLiteral("pushButtonSectionFillingColor"));

    verticalLayoutSectionFilling2->addWidget(m_pPushButtonSectionFillingColor);

    m_pComboBoxSectionFillingHatchPattern = NEW_AS_QT_CHILD(QComboBox, horizontalLayoutWidget_4);
    m_pComboBoxSectionFillingHatchPattern->setObjectName(QStringLiteral("comboBoxSectionFillingHatchPattern"));

    verticalLayoutSectionFilling2->addWidget(m_pComboBoxSectionFillingHatchPattern);

    m_pLineEditSectionHatchAngle = NEW_AS_QT_CHILD(QLineEdit, horizontalLayoutWidget_4);
    m_pLineEditSectionHatchAngle->setObjectName(QStringLiteral("lineEditSectionHatchAngle"));

    verticalLayoutSectionFilling2->addWidget(m_pLineEditSectionHatchAngle);
    m_pLineEditSectionHatchScale = NEW_AS_QT_CHILD(QLineEdit, horizontalLayoutWidget_4);
    m_pLineEditSectionHatchScale->setObjectName(QStringLiteral("lineEditSectionHatchScale"));

    verticalLayoutSectionFilling2->addWidget(m_pLineEditSectionHatchScale);


    horizontalLayoutSectionFilling->addLayout(verticalLayoutSectionFilling2);

    pushButtonOk = NEW_AS_QT_CHILD(QPushButton, centralWidget);
    pushButtonOk->setObjectName(QStringLiteral("pushButtonOk"));
    pushButtonOk->setGeometry(QRect(110, 330, 80, 26));
    pushButtonCancel = NEW_AS_QT_CHILD(QPushButton, centralWidget);
    pushButtonCancel->setObjectName(QStringLiteral("pushButtonCancel"));
    pushButtonCancel->setGeometry(QRect(200, 330, 80, 26));

    this->setWindowTitle(QString::fromStdWString(GBMP_TR(L"面样式设置333")));
    groupBoxShading->setTitle(QString::fromStdWString(GBMP_TR(L"着色")));
    labelFaceColor->setText(QString::fromStdWString(GBMP_TR(L"投影面颜色")));
    m_pPushButtonFaceColor->setText(QString());
    labelSectionFaceColor->setText(QString::fromStdWString(GBMP_TR(L"截面颜色")));
    m_pPushButtonSectionFaceColor->setText(QString());
    groupBoxProjectionFaceFilling->setTitle(QString::fromStdWString(GBMP_TR(L"投影面填充")));
    labelProjectionFaceFillingColor->setText(QString::fromStdWString(GBMP_TR(L"颜色")));
    labelProjectionFaceFillingHatchPattern->setText(QString::fromStdWString(GBMP_TR(L"填充图案")));
    labelProjectionFaceFillingAngle->setText(QString::fromStdWString(GBMP_TR(L"填充角度")));
    labelProjectionFaceFillingScale->setText(QString::fromStdWString(GBMP_TR(L"填充缩放")));
    m_pPushButtonProjectionFaceFillingColor->setText(QString());
    groupBoxSectionFilling->setTitle(QString::fromStdWString(GBMP_TR(L"截面填充")));
    labelSectionFillingColor->setText(QString::fromStdWString(GBMP_TR(L"颜色")));
    labelSectionFillingHatchPattern->setText(QString::fromStdWString(GBMP_TR(L"填充图案")));
    labelSectionFillingAngle->setText(QString::fromStdWString(GBMP_TR(L"填充角度")));
    labelSectionFillingScale->setText(QString::fromStdWString(GBMP_TR(L"填充缩放")));
    m_pPushButtonSectionFillingColor->setText(QString());
    pushButtonOk->setText(QString::fromStdWString(GBMP_TR(L"确定")));
    pushButtonCancel->setText(QString::fromStdWString(GBMP_TR(L"取消")));

    QObject::connect(pushButtonOk, SIGNAL(clicked()), this, SLOT(OkButtonClicked()));
    QObject::connect(pushButtonCancel, SIGNAL(clicked()), this, SLOT(CancelButtonClicked())); 
    QObject::connect(m_pPushButtonFaceColor, SIGNAL(clicked()), this, SLOT(FaceColorButtonClicked()));
    QObject::connect(m_pPushButtonSectionFaceColor, SIGNAL(clicked()), this, SLOT(SectionFaceColorButtonClicked()));
    QObject::connect(m_pPushButtonProjectionFaceFillingColor, SIGNAL(clicked()), this, SLOT(ProjectionFaceHatchColorButtonClicked()));
    QObject::connect(m_pPushButtonSectionFillingColor, SIGNAL(clicked()), this, SLOT(SectionFaceHatchColorButtonClicked()));

    // 初始化控件

    // 面颜色
    m_pPushButtonFaceColor->setEnabled(true);
    QColor qColorFace(m_faceColor.R, m_faceColor.G, m_faceColor.B, m_faceColor.A);
    m_pPushButtonFaceColor->setStyleSheet(QString("background-color:%1").arg(qColorFace.name()));

    m_pPushButtonSectionFaceColor->setEnabled(true);
    QColor qColorSectionFace(m_sectionFaceColor.R, m_sectionFaceColor.G, m_sectionFaceColor.B, m_sectionFaceColor.A);
    m_pPushButtonSectionFaceColor->setStyleSheet(QString("background-color:%1").arg(qColorSectionFace.name()));

    // 面填充
    std::vector<std::wstring> hatchPatternNames;
    std::vector<IElement*> HatchPatternElements = m_doc->GetElementsByCategory(BuiltInCategoryUniIdentities::BICU_HATCH_PATTERN);
    FOR_EACH(pHatchPatternElement, HatchPatternElements)
    {
        IGenericElement* pHatchPatternEle = quick_cast<IGenericElement>(pHatchPatternElement);
        if (!pHatchPatternEle)
            continue;

        DBG_WARN_AND_CONTINUE_UNLESS(pHatchPatternEle, L"pHatchPatternEle为空",L"GDMPLab",L"2024-03-30");
        IExternalObject* pExternalObject = pHatchPatternEle->GetExternalObject();
        DBG_WARN_AND_CONTINUE_UNLESS(pExternalObject, L"pExternalObject为空",L"GDMPLab",L"2024-03-30");
        IFillPattern* pHatchPatternElement = quick_cast<IFillPattern>(pExternalObject);
        DBG_WARN_AND_CONTINUE_UNLESS(pHatchPatternElement, L"pHatchPatternElement为空",L"GDMPLab",L"2024-03-30");
        const IFillPatternData* pHatchPattern = pHatchPatternElement->GetFillPatternData();
        DBG_WARN_AND_CONTINUE_UNLESS(pHatchPattern, L"pHatchPattern1为空",L"GDMPLab",L"2024-03-30");
        std::wstring name = pHatchPattern->GetName();
        hatchPatternNames.push_back(name);
    }
    for (int iFaceType = 0; iFaceType <= (int)(HatchFaceType::Section); ++iFaceType)
    {
        gcmp::Color     FaceHatchColor;
        std::wstring    FaceHatchPattern;
        QPushButton*    pPushButtonFaceHatchColor = nullptr;
        QComboBox*      pComboBoxFaceHatchPattern = nullptr;
        QLineEdit*      pLineEditFaceHatchAngle = nullptr;
        QLineEdit*      pLineEditFaceHatchScale = nullptr;

        if (iFaceType == (int)HatchFaceType::Projection)
        {
            FaceHatchColor = m_projectionFaceHatchColor;
            FaceHatchPattern = m_projectionFaceHatchPattern;
            pPushButtonFaceHatchColor = m_pPushButtonProjectionFaceFillingColor;
            pComboBoxFaceHatchPattern = m_pComboBoxProjectionFaceHatchPattern;
            pLineEditFaceHatchAngle = m_pLineEditProjectionFaceHatchAngle;
                pLineEditFaceHatchScale = m_pLineEditProjectionFaceHatchScale;

        }
        else if (iFaceType == (int)HatchFaceType::Section)
        {
            FaceHatchColor = m_sectionFaceHatchColor;
            FaceHatchPattern = m_sectionFaceHatchPattern;
            pPushButtonFaceHatchColor = m_pPushButtonSectionFillingColor;
            pComboBoxFaceHatchPattern = m_pComboBoxSectionFillingHatchPattern;
            pLineEditFaceHatchAngle = m_pLineEditSectionHatchAngle;
            pLineEditFaceHatchScale = m_pLineEditSectionHatchScale;
        }
        else
        {
            DBG_WARN(L"不支持的填充面类型",L"GDMPLab",L"2024-03-30");
            continue;
        }

        // 颜色
        pPushButtonFaceHatchColor->setEnabled(true);
        QColor qHatchColor
            ( FaceHatchColor.R
            , FaceHatchColor.G
            , FaceHatchColor.B
            , FaceHatchColor.A );
        pPushButtonFaceHatchColor->setStyleSheet(QString("background-color:%1").arg(qHatchColor.name()));

        // 图案
        pComboBoxFaceHatchPattern->setEnabled(true);
        int nPattern = static_cast<int>(hatchPatternNames.size());
        if (nPattern <= 0)
        {
            DBG_WARN(L"没有面填充图案？",L"GDMPLab",L"2024-03-30");
            pComboBoxFaceHatchPattern->setEnabled(false);
        }
        else
        {
            int iCurrPattern = -1;

            QStringList hatchPatternsList;
            for (int iPattern = 0; iPattern < nPattern; ++iPattern)
            {
                std::wstring patternString = hatchPatternNames[iPattern];
                hatchPatternsList << QString::fromStdWString(GBMP_TR(patternString));
                if (patternString == FaceHatchPattern)
                    iCurrPattern = iPattern;
            }                                
            pComboBoxFaceHatchPattern->addItems(hatchPatternsList);

            if (iCurrPattern == -1)
            {
                pComboBoxFaceHatchPattern->setCurrentIndex(0);
                IFillPattern* pHatchPatternElement = IFillPattern::GetFillPatternByName(m_doc, hatchPatternNames[0]);
                DBG_WARN_UNLESS(pHatchPatternElement,L"pHatchPatternElement无效",L"GDMPLab",L"2024-03-30");
                const IFillPatternData* pHatchPattern = pHatchPatternElement->GetFillPatternData();
                DBG_WARN_UNLESS(pHatchPattern, L"pHatchPattern无效",L"GDMPLab",L"2024-03-30");
                pLineEditFaceHatchAngle->setText(QString::number(pHatchPattern->GetRotateAngle(), 10, 4));
                pLineEditFaceHatchScale->setText(QString::number(pHatchPattern->GetScale(), 10, 4));
            }
            else
            {                                    
                pComboBoxFaceHatchPattern->setCurrentIndex(iCurrPattern);
                IFillPattern* pHatchPatternElement = IFillPattern::GetFillPatternByName(m_doc, hatchPatternNames[iCurrPattern]);
                DBG_WARN_UNLESS(pHatchPatternElement, L"pHatchPatternElement无效",L"GDMPLab",L"2024-03-30");
                const IFillPatternData* pHatchPattern = pHatchPatternElement->GetFillPatternData();
                DBG_WARN_UNLESS(pHatchPattern, L"pHatchPattern无效",L"GDMPLab",L"2024-03-30");
                pLineEditFaceHatchAngle->setText(QString::number(pHatchPattern->GetRotateAngle(), 10, 4));
                pLineEditFaceHatchScale->setText(QString::number(pHatchPattern->GetScale(), 10, 4));
            }
        }        
    }
        
    //
    QMetaObject::connectSlotsByName(this);
}


const gcmp::Color& FaceStyleSettingDialog::GetSectionFaceColor() const
{
    if (DEBUG_MODE(DontUseSectionFaceColor))
        return m_faceColor;
    else
        return m_sectionFaceColor;
}

void FaceStyleSettingDialog::OkButtonClicked()
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_doc, L"文档为空",L"GDMPLab",L"2024-03-30");

    std::vector<std::wstring> hatchPatternNames;
    std::vector<IElement*> HatchPatternElements = m_doc->GetElementsByCategory(BuiltInCategoryUniIdentities::BICU_HATCH_PATTERN);
    FOR_EACH(pHatchPatternElement, HatchPatternElements)
    {
        IGenericElement* pHatchPatternEle = quick_cast<IGenericElement>(pHatchPatternElement);
        if (!pHatchPatternEle)
            continue;

        DBG_WARN_AND_CONTINUE_UNLESS(pHatchPatternEle, L"pHatchPatternEle为空",L"GDMPLab",L"2024-03-30");
        IExternalObject* pExternalObject = pHatchPatternEle->GetExternalObject();
        DBG_WARN_AND_CONTINUE_UNLESS(pExternalObject, L"pExternalObject为空",L"GDMPLab",L"2024-03-30");
        IFillPattern* pHatchPatternElement = quick_cast<IFillPattern>(pExternalObject);
        DBG_WARN_AND_CONTINUE_UNLESS(pHatchPatternElement, L"pHatchPatternElement为空",L"GDMPLab",L"2024-03-30");
        const IFillPatternData* pHatchPattern = pHatchPatternElement->GetFillPatternData();
        DBG_WARN_AND_CONTINUE_UNLESS(pHatchPattern, L"pHatchPattern1为空",L"GDMPLab",L"2024-03-30");
        std::wstring name = pHatchPattern->GetName();
        hatchPatternNames.push_back(name);
    }

    m_projectionFaceHatchPattern = hatchPatternNames[m_pComboBoxProjectionFaceHatchPattern->currentIndex()];
    m_sectionFaceHatchPattern = hatchPatternNames[m_pComboBoxSectionFillingHatchPattern->currentIndex()];
    m_projectionFaceHatchAngle = m_pLineEditProjectionFaceHatchAngle->text().toDouble();
    m_projectionFaceHatchScale = m_pLineEditProjectionFaceHatchScale->text().toDouble();
    m_sectionHatchAngle = m_pLineEditSectionHatchAngle->text().toDouble();
    m_sectionHatchScale = m_pLineEditSectionHatchScale->text().toDouble();
    QDialog::accept();
}

void FaceStyleSettingDialog::CancelButtonClicked()
{
    QDialog::reject();
}

void FaceStyleSettingDialog::FaceColorButtonClicked()
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_doc, L"文档为空",L"GDMPLab",L"2024-03-30");

    QColorDialog qcolorDialog;
    QColor qcolor(m_faceColor.R, m_faceColor.G, m_faceColor.B, m_faceColor.A);
    QColor resColor = qcolorDialog.getColor(qcolor,this);
    if (!resColor.isValid())
        return;
    m_pPushButtonFaceColor->setStyleSheet(QString("background-color:%1").arg(resColor.name()));
    m_faceColor = Color(resColor.red(), resColor.green(), resColor.blue(), resColor.alpha());
}

void FaceStyleSettingDialog::SectionFaceColorButtonClicked()
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_doc, L"文档为空",L"GDMPLab",L"2024-03-30");

    QColorDialog qcolorDialog;
    QColor qcolor(m_sectionFaceColor.R, m_sectionFaceColor.G, m_sectionFaceColor.B, m_sectionFaceColor.A);
    QColor resColor = qcolorDialog.getColor(qcolor, this);
    if (!resColor.isValid())
        return;
    m_pPushButtonSectionFaceColor->setStyleSheet(QString("background-color:%1").arg(resColor.name()));
    m_sectionFaceColor = Color(resColor.red(), resColor.green(), resColor.blue(), resColor.alpha());
}

void FaceStyleSettingDialog::ProjectionFaceHatchColorButtonClicked()
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_doc, L"文档为空",L"GDMPLab",L"2024-03-30");

    QColorDialog qcolorDialog;
    QColor qcolor(m_projectionFaceHatchColor.R, m_projectionFaceHatchColor.G, m_projectionFaceHatchColor.B, m_projectionFaceHatchColor.A);
    QColor resColor = qcolorDialog.getColor(qcolor,this);
    if (!resColor.isValid())
        return;
    m_pPushButtonProjectionFaceFillingColor->setStyleSheet(QString("background-color:%1").arg(resColor.name()));
    m_projectionFaceHatchColor = Color(resColor.red(), resColor.green(), resColor.blue(), resColor.alpha());
}

void FaceStyleSettingDialog::SectionFaceHatchColorButtonClicked()
{
    DBG_WARN_AND_RETURN_VOID_UNLESS(m_doc, L"文档为空",L"GDMPLab",L"2024-03-30");

    QColorDialog qcolorDialog;
    QColor qcolor(m_sectionFaceHatchColor.R, m_sectionFaceHatchColor.G, m_sectionFaceHatchColor.B, m_sectionFaceHatchColor.A);
    QColor resColor = qcolorDialog.getColor(qcolor,this);
    if (!resColor.isValid())
        return;
    m_pPushButtonSectionFillingColor->setStyleSheet(QString("background-color:%1").arg(resColor.name()));
    m_sectionFaceHatchColor = Color(resColor.red(), resColor.green(), resColor.blue(), resColor.alpha());
}
